import { computed, ref } from 'vue'
import { defineStore } from 'pinia'
import { $t } from '@/i18n'
import { feedbackReasons } from '@/constant/index.js'

export const useFeedback = defineStore('feedback', () => {
  const reasons = computed(() =>
    feedbackReasons.map(({ id, reason }) => ({ id, reason, content: $t(`feedback.reason.${id}`) })),
  )
  const reason = ref(null)
  const reasonErr = ref('')
  const content = ref('')
  const contentErr = ref('')
  const files = ref([])
  const filesUrl = ref([])

  function reset() {
    reason.value = null
    content.value = ''
    contentErr.value = ''
    files.value = []
    filesUrl.value = []
  }

  return {
    reasons,
    reason,
    reasonErr,
    content,
    contentErr,
    files,
    filesUrl,
    reset,
  }
})
